package datatypes;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Service {

	public List<Duty> duties;
	public int numOfParticipants;

	public Service() {
		duties = new ArrayList<Duty>();
	}

	// service functions

	public void addDuty(Duty duty) {
		this.duties.add(duty);
	}

	public Duty getDutyBuID(int DID) {
		for (Duty duty : this.duties) {
			if (duty.getDID() == DID) {
				return duty;
			}
		}

		return null;
	}

	public void removeDuty(int DID) {
		for (Duty duty : duties) {
			if (duty.getDID() == DID) {
				this.duties.remove(duty);
				break;
			}
		}
	}

	public Duty getMostExpensiveDuty() {
		Duty maxDuty = null;
		double max = 0;
		for (Duty d : duties) {
		   if(d.getTotalPoints() > max){
			   max = d.getTotalPoints();
			   maxDuty = d;
		   }
		}
		
		return maxDuty;
	}

	public int getNumOfParticipants() {
		return this.numOfParticipants;
	}

	public void setNumOfParticipants(int numOfParticipants) {
		this.numOfParticipants = numOfParticipants;
	}

	public void sortDuties() {
		Collections.sort(duties);

	}

	public List<Duty> getDuties() {
		return this.duties;
	}
}
